// 把token放到头部
$(document).ajaxSend(function(event, jqxhr, settings) {
   jqxhr.setRequestHeader("access-token",sessionStorage.getItem("accessToken"));
});
// 监听ajax的code失效与否
$.ajaxSetup({
   statusCode:{
     401:function(data){
         if(data.responseJSON.code=='401'){
               parent.parent.layer.alert('登录已过期请重新登录',function(){
                  sessionStorage.clear();
                  localStorage.clear();
                  top.location.href = "../login.html";
               })
         }
      }
   }
})

function workSheet(form,docId,type){
    $.ajax({
       url: 'gt/opm/dataDict/query/tree', //请求地址
       type: "get", //提交的方式S
       data: {"type":type},
       dataType: "JSON", //返回类型 TEXT字符串 JSON XML
       headers: { "Content-Type": "application/json;charset=UTF-8" },
       beforeSend: function(request) {
         loading=layer.load(2);
      
      },
      success: function(data) {
         layer.closeAll('loading');
          var data=data.data;
          $("#"+docId).children("option").remove();
          $("#"+docId).append(
             '<option value=""></option>'
          )
          $.each(data,function(i,v){
             $("#"+docId).append(
                '<option value="'+v.code+'">'+v.value+'</option>'
             )
          })
          form.render("select")
       }
   })
 }
 function workSheetOnSelect(form,type,typeCode){
    $.ajax({
       url: 'gt/opm/dataDict/query/tree', //请求地址
       type: "get", //提交的方式S
       data: {"type":type},
       dataType: "JSON", //返回类型 TEXT字符串 JSON XML
       headers: { "Content-Type": "application/json;charset=UTF-8" },
       beforeSend: function(request) {
         loading=layer.load(2);
      
      },
      success: function(data) {
         layer.closeAll('loading');
          var data=data.data;
          $("#questionContent option").remove();
          $.each(data,function(i,v){
             $("#questionContent").append(
                '<option value=""></option>'
             )
             if(v.childList!=''){
                $.each(v.childList,function(a,c){
                   if(v.code==typeCode){
                      $("#questionContent").append(
                         '<option value="'+c.code+'">'+c.value+'</option>'
                         )
                   }
                })
             form.render("select")
             }
          })
       }
   })
 }
 function userDept(form,docId){
    $.ajax({
        url: 'gt/opm/user/userDept', //请求地址
        type: "get", //提交的方式S
        dataType: "JSON", //返回类型 TEXT字符串 JSON XML
        headers: { "Content-Type": "application/json;charset=UTF-8" },
        beforeSend: function(request) {
         loading=layer.load(2);
      
         },
         success: function(data) {
         layer.closeAll('loading');
            var data=data.data;
            $("#"+docId).children("option").remove();
            $("#"+docId).append(
               '<option value=""></option>'
            )
            $.each(data,function(i,v){
               $("#"+docId).append(
                  '<option value="'+v+'">'+v+'</option>'
               )
            })
            form.render("select")
        }
    })
 }
 function createDept(form,docId){
   $.ajax({
       url: 'gt/opm/workSheet/createDept', //请求地址
       type: "get", //提交的方式S
       dataType: "JSON", //返回类型 TEXT字符串 JSON XML
       headers: { "Content-Type": "application/json;charset=UTF-8" },
       beforeSend: function(request) {
         loading=layer.load(2);
      },
      success: function(data) {
         layer.closeAll('loading');
           var data=data.data;
           $("#"+docId).children("option").remove();
           $("#"+docId).append(
              '<option value=""></option>'
           )
           $.each(data,function(i,v){
              $("#"+docId).append(
                 '<option value="'+v+'">'+v+'</option>'
              )
           })
           form.render("select")
       }
   })
}


  